]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensionDownloader: Use registered D-Bus error
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 31 Jan 2024 16:44:10 +0000 (17:44 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 31 Jan 2024 19:58:31 +0000 (20:58 +0100)
Instead of returning ad-hoc errors, register a custom error domain
and return appropriate GLib.Errors.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3159>

js/misc/dbusErrors.js
js/ui/extensionDownloader.js

index 6cb8a83b1c49cf379937e6c298e043c5c3ef7abe..5081e374e46829cc595f6d950a7086cb2bc75396 100644 (file)
@@ -41,3 +41,13 @@ const notificationErrorNames = [
 export const NotificationErrors =
     registerErrorDomain('Notifications', notificationErrorNames, 'org.gtk');
 export const NotificationError = createErrorEnum(notificationErrorNames);
+
+const extensionErrorNames = [
+    'InfoDownloadFailed',
+    'DownloadFailed',
+    'ExtractFailed',
+    'EnableFailed',
+];
+export const ExtensionErrors =
+    registerErrorDomain('Extensions', extensionErrorNames);
+export const ExtensionError = createErrorEnum(extensionErrorNames);
index 6daca8155116433cc293f6e85f2184a423beada0..6486bbcada752886f0ef028351d371d4e17746a0 100644 (file)
@@ -13,6 +13,8 @@ import * as FileUtils from '../misc/fileUtils.js';
 import * as Main from './main.js';
 import * as ModalDialog from './modalDialog.js';
 
+import {ExtensionErrors, ExtensionError} from '../misc/dbusErrors.js';
+
 Gio._promisify(Soup.Session.prototype, 'send_and_read_async');
 Gio._promisify(Gio.OutputStream.prototype, 'write_bytes_async');
 Gio._promisify(Gio.IOStream.prototype, 'close_async');
@@ -50,8 +52,9 @@ export async function installExtension(uuid, invocation) {
         info = JSON.parse(decoder.decode(bytes.get_data()));
     } catch (e) {
         Main.extensionManager.logExtensionError(uuid, e);
-        invocation.return_dbus_error(
-            'org.gnome.Shell.ExtensionError', e.message);
+        invocation.return_error_literal(
+            ExtensionErrors, ExtensionError.INFO_DOWNLOAD_FAILED,
+            e.message);
         return;
     }
 
@@ -243,6 +246,18 @@ export async function checkForUpdates() {
     }
 }
 
+class ExtractError extends Error {
+    get name() {
+        return 'ExtractError';
+    }
+}
+
+class EnableError extends Error {
+    get name() {
+        return 'EnableError';
+    }
+}
+
 const InstallExtensionDialog = GObject.registerClass(
 class InstallExtensionDialog extends ModalDialog.ModalDialog {
     _init(uuid, info, invocation) {
@@ -293,19 +308,31 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
                 null);
             checkResponse(message);
 
-            await extractExtensionArchive(bytes, dir);
+            try {
+                await extractExtensionArchive(bytes, dir);
+            } catch (e) {
+                throw new ExtractError(e.message);
+            }
 
             const extension = Main.extensionManager.createExtensionObject(
                 this._uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
             Main.extensionManager.loadExtension(extension);
             if (!Main.extensionManager.enableExtension(this._uuid))
-                throw new Error(`Cannot enable ${this._uuid}`);
+                throw new EnableError(`Cannot enable ${this._uuid}`);
 
             this._invocation.return_value(new GLib.Variant('(s)', ['successful']));
         } catch (e) {
+            let code;
+            if (e instanceof ExtractError)
+                code = ExtensionError.EXTRACT_FAILED;
+            else if (e instanceof EnableError)
+                code = ExtensionError.ENABLE_FAILED;
+            else
+                code = ExtensionError.DOWNLOAD_FAILED;
+
             log(`Error while installing ${this._uuid}: ${e.message}`);
-            this._invocation.return_dbus_error(
-                'org.gnome.Shell.ExtensionError', e.message);
+            this._invocation.return_error_literal(
+                ExtensionErrors, code, e.message);
         }
     }
 });